<!DOCTYPE html>
<html>
<head>
  <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
  <title>The source code</title>
  <link href="../resources/prettify/prettify.css" type="text/css" rel="stylesheet" />
  <script type="text/javascript" src="../resources/prettify/prettify.js"></script>
  <style type="text/css">
    .highlight { display: block; background-color: #ddd; }
  </style>
  <script type="text/javascript">
    function highlight() {
      document.getElementById(location.hash.replace(/#/, "")).className = "highlight";
    }
  </script>
</head>
<body onload="prettyPrint(); highlight();">
  <pre class="prettyprint lang-js">if(!jslet.ui.table) {
	jslet.ui.table = {};
}

/*
 * Find dialog for DBTable
 */
jslet.ui.table.FindDialog = function (dbContainer) {
	var _dialog;
	var _dataset = dbContainer.dataset();
	var _containerEl = dbContainer.el;
	var _currfield = null;
	var _findingField = null;
	var _left = -1;
	var _top = -1;
	function initialize() {
		var opt = { type: 'window', caption: jslet.formatMessage(jsletlocale.findDialog.caption, ['']), isCenter: false, resizable: true, minimizable: false, maximizable: false, 
				stopEventBubbling: true, styleClass: 'jl-finddlg'};
		_dialog = jslet.ui.createControl(opt, _containerEl);
		_dialog.onClosed(function(){
			return 'hidden';
		});
			
		var content = '&lt;div class=&quot;input-group input-group-sm&quot;&gt;&lt;input class=&quot;form-control jl-finddlg-value&quot; placeholder=&quot;' + 
		jsletlocale.findDialog.placeholder + '&quot;/&gt;' + 
		'&lt;div class=&quot;input-group-btn&quot;&gt;&lt;button class=&quot;btn btn-default jl-finddlg-find&quot;&gt;&lt;i class=&quot;fa fa-search&quot; /&gt;&lt;/button&gt;&lt;/div&gt;&lt;/div&gt;';
		
		_dialog.setContent(content);
		_dialog.onPositionChanged(function(left, top) {
			_left = (left &gt; 0? left: 0);
			_top = (top &gt; 0? top: 0);
		});
		var dlgEl = _dialog.el;

		var jqFindingValue = jQuery(dlgEl).find('.jl-finddlg-value');
		var isStart = true;
		jqFindingValue.on('keydown', function(event){
			if(event.keyCode === jslet.ui.KeyCode.ENTER) {
				findData();
	       		event.stopImmediatePropagation();
				event.preventDefault();
				return false;
			}
			isStart = true;
		});
		
		var jqFind = jQuery(dlgEl).find('.jl-finddlg-find');
		jqFind.on('click', function(event) {
			findData();
		});

		function findData() {
			if(_dataset.recordCount() &lt; 2) {
				return;
			}
			var findingValue = jqFindingValue.val(),
				currRecno = 0;
			if(!isStart) {
				currRecno = _dataset.recno() + 1;
			}
			var options = {startRecno: currRecno, findingByText: true, matchType: 'any'};
			var found = _dataset.findByField(_findingField, findingValue, options);
			isStart = !found;
			if(!found) {
				if(currRecno &gt; 0) { //If not found, find from the first position.
					findData();
				}
			}
			return found;
		}
	}
	
	this.show = function(left, top) {
		if(!_findingField) {
			return;
		}
		if(_left &gt;= 0) {
			left = _left;
		}
		if(_top &gt;= 0) {
			top = _top;
		}
		left = left || 0;
		top = top || 0;
		_dialog.show(left, top);
		this.focus();
	};
	
	this.hide = function() {
		_dialog.hide();
	};
	
	this.findingField = function(findingField) {
		if(findingField === undefined) {
			return _findingField;
		}
		var oldField = _findingField;
		_findingField = findingField;
		if(_findingField) {
			var fldObj = _dataset.getField(_findingField);
			if(fldObj) {
				var dataType = fldObj.getType();
				if(dataType === jslet.data.DataType.ACTION || dataType === jslet.data.DataType.EDITACTION) {
					_findingField = null;
					return;
				}
				_dialog.changeCaption(jslet.formatMessage(jsletlocale.findDialog.caption, [fldObj.label()]));
				if(oldField != findingField) {
					jQuery(_dialog.el).find('.jl-finddlg-value').val('');
				}
			}
		}
	};
	
	this.focus = function() {
		jQuery(_dialog.el).find('.jl-finddlg-value').focus();
	};
	
	this.destroy = function() {
		_dialog.destroy();
	};
	
	initialize();
};


</pre>
</body>
</html>
